//
//  Mythread.m
//  8多线程
//
//  Created by zhengwei on 2/13/16.
//  Copyright © 2016 zhengwei. All rights reserved.
//

#import "Mythread.h"

@implementation Mythread
-(void)testThread{
//    1 NSOperationQueue:
    self.myQueue = [[NSOperationQueue alloc]init];
    [self threadAction3];
}
-(void)threadAction1{
//   1 Block Creat
    NSBlockOperation *block = [NSBlockOperation blockOperationWithBlock:^{
        NSLog(@"%@",[NSThread currentThread]);
    }];
//   2 Add Queue
    [self.myQueue addOperation:block];
}
-(void)threadAction2{
//   1 用户名密码登录 2 开始买票 3 开始付款
    NSBlockOperation *block1 = [NSBlockOperation blockOperationWithBlock:^{
        NSLog(@"用户名密码登录 %@",[NSThread currentThread]);
    }];
    NSBlockOperation *block2 = [NSBlockOperation blockOperationWithBlock:^{
        NSLog(@"开始买票 %@",[NSThread currentThread]);
    }];
    NSBlockOperation *block3 = [NSBlockOperation blockOperationWithBlock:^{
        NSLog(@"开始付款 %@",[NSThread currentThread]);
    }];
    [block2 addDependency:block1];
    [block3 addDependency:block2];
    [self.myQueue addOperation:block1];
    [self.myQueue addOperation:block2];
    [self.myQueue addOperation:block3];
//  1 线程之间的运行是没有先后顺序优先级
}
-(void)threadAction3{
    self.myQueue.maxConcurrentOperationCount = 2;
    for (int i = 0; i < 10; i++) {
        [self.myQueue addOperationWithBlock:^{
            NSLog(@"当前最大并发为2");
        }];
    }
}
@end
